﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace blackhouse.Web.Controls.TemplateControl {
    public class TemplateControl : Panel {

        #region Properties

        public string TemplateId { get; set; }

        #endregion

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            foreach (Control control in this.Controls) {
                ITemplateDrop iTemp = control as ITemplateDrop;
                if (iTemp != null)
                    iTemp.SetAsTemplate();
            }
        }

        public override void RenderBeginTag(HtmlTextWriter writer) {

            writer.AddAttribute("type", "text/x-jquery-tmpl");
            if (string.IsNullOrEmpty(this.TemplateId))
                this.TemplateId = this.ClientID + "_tmpl";
            writer.AddAttribute("id", this.TemplateId);
            writer.AddAttribute("template-id", this.TemplateId);
            writer.RenderBeginTag("script");
        }

        public override void RenderEndTag(HtmlTextWriter writer) {
            writer.RenderEndTag();
        }
    }
}